<template>
  <div v-loading="loading">
    <!-- 统计相关 开始 -->
    <div class="total-container">
      <!-- 活动营销数据 -->
      <div class="common-container">
        <AppMainSubTitle title="活动营销数据" />
        <AppTableStatisticsCard :statistics-card-data="statisticsCardMarketingData" />
      </div>

      <!-- 参与活动商品汇总 -->
      <div class="common-container">
        <AppMainSubTitle title="参与活动商品汇总" />
        <el-table
          :data="goodsList"
          border
          stripe
          style="width: 500px"
          empty-text="暂无数据"
        >
          <el-table-column
            prop="goodsCode"
            label="商品编码"
          />
          <el-table-column
            prop="totalNum"
            label="销售数量/个"
          />
          <el-table-column
            prop="totalDiscount"
            label="优惠金额/元"
          >
            <template slot-scope="scope">
              {{ scope.row.totalDiscount/100 }}
            </template>
          </el-table-column>

        </el-table>
      </div>

    </div>
    <!-- 统计相关 结束-->
  </div>
</template>

<script>
import { singleItemData } from '@/api/marketing'

export default {
  props: {
    activityDetail: {
      require: true
    }
  },
  data() {
    return {
      // 配置
      // 状态
      loading: false,
      // 数据
      totalFilterForm: {
        date: ''
      },
      statisticsCardMarketingData: [
        {
          title: '累计销售商品 / 个',
          value: 0,
          describeList: [],
          detailList: []
        },
        {
          title: '累计优惠 / 元',
          value: 0,
          describeList: [],
          detailList: []
        }
      ],
      goodsList: []
    }
  },
  computed: {},
  watch: {},
  beforeCreate() {
  },
  created() {
  },
  beforeMount() {
  },
  mounted() {
    this.fetchData()
  },
  beforeUpdate() {
  },
  update() {
  },
  activated() {
  },
  deactivated() {
  },
  beforeDestroy() {
  },
  destroyed() {
  },
  methods: {
    /**
     * 数据组
     */
    // 获取统计
    fetchData() {
      this.loading = true
      const params = { activityId: this.activityDetail.id }
      singleItemData(params)
        .then((res) => {
          if (res.data) {
            this.statisticsCardMarketingData[0].value = res.data.totalSell || 0
            this.statisticsCardMarketingData[1].value = res.data.totalDiscountAmount / 100 || 0
            this.goodsList = res.data.detail || []
          }
        })
        .finally(() => {
          this.loading = false
        })
    }
    /**
     * 按钮组
     */
    /**
     * 状态组
     */
    /**
     * 方法组
     */
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
/* 统计 */
.total-container {
  .common-container{
    margin-bottom: 10px;
  }
}
</style>
